<template>
<div class="entering-merchant views-container">
    <el-dialog @close="clearReason" :visible.sync="dialogVisibleImg" width="30%" custom-class="reset-pwd wlm-form-dialog dialog-table">
        <div class="wlm-form" v-if="dialogVisibleImg">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">拒绝审核</span>
            </div>
            <el-scrollbar wrap-class="scrollbar-wrapper">
                <div class="wlm-form-content">
                    <div class="wlm-dialog-main">
                        <div class="wlm-dialog-content">
                            <el-form ref="userForm" :model="openDialogText"  size="small" label-width="120px" class="retail-form" label-position="right">
                                <el-form-item label="原因" prop="merchantlog">
                                    <el-input v-if="!isReasonText" type="textarea" :autosize="{ minRows: 4, maxRows: 4}" v-model="reason">
                                    </el-input>
                                    <p v-if="isReasonText">{{reasonText}}</p>
                                </el-form-item>
                            </el-form>
                        </div>
                    </div>
                </div>
            </el-scrollbar>
        </div>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
            <el-button v-if="isReasonText" size="small" type="primary" @click="dialogVisibleImg=false">关闭</el-button>
            <el-button v-if="!isReasonText" size="small" type="primary" @click="reasonSave">确定</el-button>
        </footer>
    </el-dialog>
    <div class="wlm-table">
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="80px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="商家名称：" class="search">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.business_name" placeholder="请输入姓名" style="width:175px;"></el-input>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-tabs v-model="tableFormatData.userTable.files.status" type="card" @tab-click="filesSerch">
                <el-tab-pane label="全部申请" name="0"></el-tab-pane>
                <el-tab-pane label="待审核" name="1"></el-tab-pane>
                <el-tab-pane label="已通过" name="2"></el-tab-pane>
                <el-tab-pane label="已拒绝" name="3"></el-tab-pane>
            </el-tabs>
            <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="date" label="商家名称" >
                    <template slot-scope="scope">
                        <p>{{scope.row.business_name}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="姓名" >
                    <template slot-scope="scope">
                        <span>{{scope.row.name}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="电话" >
                    <template slot-scope="scope">
                        <span>{{scope.row.telephone}}</span>
                    </template>
                </el-table-column>
                  <el-table-column prop="name" label="所在地区" >
                    <template slot-scope="scope">
                        <span>{{scope.row.region}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="详细地址" >
                    <template slot-scope="scope">
                        <span>{{scope.row.address}}</span>
                    </template>
                </el-table-column>
               
                 <el-table-column prop="name" label="商家资质" >
                    <template slot-scope="scope">
                        <!-- <span>{{scope.row.region}}</span> -->
                        <div v-for="(item,index) in scope.row.quaimg" :key="index">
                            <!-- {{item}} -->
                             <el-popover
                                placement="top-start"
                                width="330"
                                trigger="hover"
                                >
                                 <img style="height:300px;width:300px;" :property="item" :src="item?item:''"/>
                                <img style="height:50px;width:50px;" slot="reference" :src="item?item:''"/>
                              </el-popover>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="状态" >
                    <template slot-scope="scope">
                        <span v-if="scope.row.status==1">待审核</span>
                        <span v-if="scope.row.status==2">通过</span>
                        <span v-if="scope.row.status==3">拒绝</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="申请时间" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.update_time }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" >
                    <template slot-scope="scope">
                        <div class="operation-group" >
                            <el-button v-if="scope.row.status==1" class="wlm-text" type="text" @click="entering(scope.row.id)">通过</el-button>
                            <div v-if="scope.row.status==1" class="btn-line"></div>
                            <el-button v-if="scope.row.status==1" class="wlm-text" type="text" @click="dialogVisibleImg=true,reasonId=scope.row.id">拒绝</el-button>
                              <el-button class="wlm-text" type="text"  @click="delTableItem(scope.row.id)">删除</el-button>
                            <el-button v-if="scope.row.status==3" class="wlm-text" type="text" @click="dialogVisibleImg=true,reasonText=scope.row.reason,isReasonText=true">拒绝原因</el-button>
                           
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-e flex-align-c">
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  storeLive,
  liveStatusEdit,
  storeLiveDel
} from '@/api/merchant'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'EnteringMerchant',
  components: {
  },
  created() {
  },
  data() {
    return {
      reason: '',
      reasonId: '',
      reasonText: '',
      isReasonText: false,
      dialogVisibleImg: false,
      openDialogText: {},
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: storeLive,
             delList: storeLiveDel,
          },
          tableData: [],
          rowId: "id",
          files: {
            business_name: '',
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    clearReason() {
      this.reason = ''
      this.reasonId = ''
      this.isReasonText = false
      this.reasonText = ''
    },
    reasonSave() {
      liveStatusEdit({ id: this.reasonId, type: 3, reason: this.reason }).then((response) => {
        const { data: { code, data, msg } } = response
        console.log(data)
        if (code === 1) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.dialogVisibleImg = false
          this.filesSerch()
        } else {
          this.$message.error(msg)
        }
      })
    },
    entering(id) {
      this.$confirm('确定通过商家的入驻申请?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        liveStatusEdit({ id: id, type: 2, reason: '' }).then((response) => {
          const { data: { code, data, msg } } = response
          console.log(data)
          if (code === 1) {
            this.$message({
              type: 'success',
              message: '审核成功!'
            })
            this.$confirm('是否前去编辑商家详情?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.$router.push({
                path: '/merchant/businessAdd',
                query: { id: data }
              })
            }).catch(() => {
              this.filesSerch()
            })
          } else {
            this.$message.error(msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    }
  }
}
</script>
